<?php
require_once 'Zend/File/Transfer/Adapter/Http.php';
class CommonController extends Zend_Controller_Action
{
    public function uploadAction(){
    	$log = Zend_Registry::get('log');
        
        $error = "";
        $msg = "";
        $file_up ="";
        $this->_helper->layout->disableLayout();
        $this->_helper->viewRenderer->setNoRender();
          
        $upload = new Zend_File_Transfer_Adapter_Http();
          
        $filename = $upload->getFileName('picture',false);//tra ve ten cua file vua up tu client
        $folder = "temp/images/"; // duong dan thu muc se luu hinh 
       
        $upload->addValidator('Extension',true,array('jpg','gif','png'),'picture');
        $upload->addValidator('Size',true,array('min'=>'2KB','max'=>'500KB'),'picture');
        //$upload->setDestination('<duong dan den thu muc chua hinh>','picture');
      
        $upload->setDestination($folder,'picture');
         
        if(!empty($filename)){         
             if($upload->isValid()){
                $msg = 'Upload thanh cong';
                $file_up = $folder.$filename;
                $upload->receive('picture');
             }else{
                $error = 'Co loi xay ra';
             }
          }else{
             $error = 'Chon mot tap tin de upload';
          }
          $log -> info ("error: ".$error);
          $log -> info ("msg: ".$msg );
          echo "{";
          echo            "error: '" . $error . "',\n";
          echo            "msg: '" . $msg . "',\n";
          echo            "file: '" . $file_up . "'\n";
          echo "}";
          
       }
	
}

?>